<!DOCTYPE html>
<html>
    <head>
        <title>AGM销售列表</title>
        <link rel="stylesheet" href="/static/weui.min.css">
        <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
        <link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <style>
            .page, body{background-color: #fbf9fe}
            .page_title{color:#225fba}
            .hd{text-align:center}
            .bd{max-width:1000px;margin:auto;}
            .weui_label{width:4em;}
            .bd{padding-bottom:30px;}
            .weui_cell_hd img, .weui_cell_ft img{height: 40px;}
            .badge {
              background: radial-gradient( 5px -9px, circle, white 8%, red 26px );
                background: -moz-radial-gradient( 5px -9px, circle, white 8%, red 26px );
                background: -ms-radial-gradient( 5px -9px, circle, white 8%, red 26px );
                background: -o-radial-gradient( 5px -9px, circle, white 8%, red 26px );
                background: -webkit-radial-gradient( 5px -9px, circle, white 8%, red 26px );
              background-color: red;
              border: 2px solid white;
              border-radius: 12px; /* one half of ( (border * 2) + height + padding ) */
              box-shadow: 1px 1px 1px black;
              color: white;
              font: bold 15px/13px Helvetica, Verdana, Tahoma;
              height: 16px; 
              padding: 4px 3px 0 3px;
              text-align: center;
              min-width: 14px;
            }
        </style>
    </head>
    <body>
        <div class="hd">
            <h3 class="page_title">AGM销售信息</h1> 
        </div>
        <div class="bd">
            <div class="weui_cells_title">销售昵称</div>
            <div class="weui_cells">
                <div class="weui_cell">
                    <div class="weui_cell_bd weui_cell_primary">
                        <p>{{seller.get('nickname')}}</p>
                    </div>
                    <div class="weui_cell_ft"><img src="{{seller.get('headimgurl') or '/static/images/getheadimg.png'}}"/></div>
                </div>
            </div>
            {% for k1, k2 in items %}
            <div class="weui_cells_title">{{k1}}</div>
            <div class="weui_cells">
                <div class="weui_cell">
                    <div class="weui_cell_bd weui_cell_primary">
                        <p>{{seller.get(k2)}}</p>
                    </div>
                </div>
            </div>            
            {% endfor %}
            <div class="weui_btn_area">
                <button seller_id="{{seller.id}}" class="weui_btn weui_btn_default" id="refreshinfo" type="submit">更新信息</button>
            </div>
            {% if not session.get('role') %}
            {% if seller.get('accept') == 1%}
            <div class="weui_btn_area">
                <button seller_id="{{seller.id}}" class="weui_btn weui_btn_primary" id="changeshop" type="submit">更换门店</button>
            </div>             
            {% endif %}
            <div class="weui_btn_area">
                {% if seller.get('accept') == 1%}
                <button seller_id="{{seller.id}}" class="weui_btn weui_btn_warn" id="cancelbtn" type="submit">取消资格</button>
                {% elif seller.get('accept') == -1%}
                <button seller_id="{{seller.id}}" class="weui_btn weui_btn_primary" id="reacceptbtn" type="submit">重新授权</button>
                {% else %}
                <button seller_id="{{seller.id}}" class="weui_btn weui_btn_primary" id="acceptbtn" type="submit">通过审核</button>
                {% endif %}
            </div>
            {% endif %}
        </div>       
        <div class="weui_dialog_alert" id="dialog2" style="display:none">
            <div class="weui_mask"></div>
            <div class="weui_dialog">
                <div class="weui_dialog_hd"><strong class="weui_dialog_title">弹窗标题</strong></div>
                <div class="weui_dialog_bd">弹窗内容，告知当前页面信息等</div>
                <div class="weui_dialog_ft">
                    <a class="weui_btn_dialog primary">确定</a>
                </div>
            </div>
        </div>
        <div class="weui_dialog_confirm" id="dialog1" style="display:none">
            <div class="weui_mask"></div>
            <div class="weui_dialog">
                <div class="weui_dialog_hd"><strong class="weui_dialog_title">弹窗标题</strong></div>
                <div class="weui_dialog_bd">自定义弹窗内容，居左对齐显示，告知需要确认的信息等</div>
                <div class="weui_dialog_ft">
                    <a class="weui_btn_dialog default">取消</a>
                    <a class="weui_btn_dialog primary">确定</a>
                </div>
            </div>
        </div>         
    </body>    
    <script>
        dialog2 = function(title, content, sucfunc){
            var self = $('#dialog2')
            self.find('.weui_dialog_title').text(title)
            self.find('.weui_dialog_bd').html(content)
            var clickfunc = sucfunc?sucfunc:function(){self.hide();}
            self.find('.weui_btn_dialog.primary').click(clickfunc)
            self.show()
        }
        myinputdailog = function(title, content, sucfunc){
            var dailog = $('#dialog1')
            dailog.find('.weui_dialog_title').text(title)
            dailog.find('.weui_dialog_bd').html(content)
            dailog.find('.weui_btn_dialog.default').click(function(){
                dailog.hide()
            })
            dailog.find('.weui_btn_dialog.primary').unbind('click').click(sucfunc)        
            dailog.show()    
        }
        $('#dialog1 .weui_mask').click(function(){
            $('#dialog1').hide()
        }) 
        $('#acceptbtn, #cancelbtn, #reacceptbtn').click(function(e){
            var self = $(this)
            var sellerid = self.attr('seller_id')
            var postdata
            var msg = ['通过', '审核']
            if (self.attr('id') == 'cancelbtn'){
                msg = ['取消', '资格']
                postdata = {'cancel': true}
            }
            if (self.attr('id') == 'reacceptbtn'){
                msg = ['重新通过', '授权']
            }
            $.post('manage?action=acceptseller&sellerid='+sellerid, postdata).done(function(data){
                console.info(data)
                if(data=='acceptsuccess'){
                    dialog2(msg[0]+msg[1] + '成功', '<i class="weui_icon_msg weui_icon_success"></i><div>已经成功'+msg[0]+'该销售用户的'+msg[1]+'<br/>点击确定键返回销售用户列表</div>', function(){location.replace('sellerlist')})
                }
            })
        })
        $('#changeshop').click(function(){
            var self = $(this)
            var shopcode0 = $('.weui_cell_bd.weui_cell_primary p').eq(3).text()
            var shopname0 = $('.weui_cell_bd.weui_cell_primary p').eq(4).text()
            var sucf = function(){
                $('#dialog1').hide()
                var shopcode = $('#inputshopcode').val()
                var shopname = $('#inputshopname').val()
                var sellerid = self.attr('seller_id')
                $.post('manage?action=sellermodifyshop&sellerid='+sellerid+'&shopname='+shopname+'&shopcode='+shopcode).done(function(data){
                    if(data=='modifydone'){
                        location.reload()
                    }else{
                        console.info(data)
                    }
                })
            }
            myinputdailog('请输入更改后的店名与代码', '<div class="weui_cells weui_cells_form "><div class="weui_cell"><div class="weui_cell_hd">代码</div><div class="weui_cell_bd weui_cell_primary"><input style="color:initial;" id="inputshopcode" class="weui_input" placeholder="请输入新商场代码" value="'+shopcode0+'"></div></div><div class="weui_cell"><div class="weui_cell_hd">店名</div><div class="weui_cell_bd weui_cell_primary"><input style="color:initial;" id="inputshopname" class="weui_input" placeholder="请输入新商场店名" value="'+shopname0+'"></div></div></div><div class="weui_cells_tips">点击确定返回后自动刷新本页面，按取消或其它位置返回</div>', sucf)
        })
        $('#refreshinfo').click(function(){
            var self = $(this)
            var sellerid = self.attr('seller_id')
            $.post('manage?action=refreshinfo&sellerid='+sellerid, function(data){
                //console.info(data)
                if(data=='refreshdone'){
                    location.reload()
                }
            })
        })
    </script>
<html>